﻿namespace WMS6.Web.CrossDock
{
    using System;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.CrossdockServiceRef;

    public class FlowThruOrderDetail : BasePage
    {
        protected HtmlInputButton btnAction;
        protected Button btnCancel;
        protected Button btnSave;
        protected DropDownList ddlStatus;
        protected HtmlForm F79563;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnOrderID;
        protected HtmlHead Head1;
        protected Label lblAllocateRuleDetail;
        protected Label lblMsg;
        protected Label lblOriginalQty;
        protected Label lblProcessedQty;
        protected Label lblShippedQty;
        protected Label lblSkuID;
        protected Label lblStatus;
        protected Label lblToProcessedQty;
        protected Label lblXorderLineID;
        protected HtmlLink mycss;
        protected Label one1;
        protected ScriptManager ScriptManager1;
        protected TextBox txtOriginalQty;
        protected TextBox txtProcessedQty;
        protected TextBox txtShippedQty;
        protected TextBox txtSkuID;
        protected TextBox txtToProcessedQty;
        protected TextBox txtXorderLineID;
        protected UpdatePanel up1;

        protected void btnCancel_Click(object sender, EventArgs e)
        {
            base.Response.Redirect("FlowThruOrder.aspx?from=edit&ID=" + this.hdnOrderID.Value, false);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (this.ddlStatus.SelectedValue.ToUpper() != "NEW")
            {
                this.lblMsg.Text = "只能修改新建单据!";
            }
            else
            {
                XorderDetailInfo xorderDetailInfo = base.DataEntityViewState as XorderDetailInfo;
                if ((xorderDetailInfo != null) && !string.IsNullOrEmpty(this.txtOriginalQty.Text))
                {
                    xorderDetailInfo.OriginalQty = decimal.Parse(this.txtOriginalQty.Text);
                }
            }
        }

        private void LoadData()
        {
            base.BindData2DDLBySysCode(this.ddlStatus, "ReceiptStatus");
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                string xorderID = base.Request.QueryString["ID"];
                this.txtXorderLineID.Text = base.Request.QueryString["LineID"];
                this.hdnOrderID.Value = xorderID;
                this.SetTextBoxByXorderDetailInfo();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadData();
            }
        }

        private void SetTextBoxByXorderDetailInfo()
        {
            XorderDetailInfo xorderDetailInfo = CrossdockServiceClientProxy.GetInstance().GetXorderDetailInfoByID(this.hdnOrderID.Value, this.txtXorderLineID.Text);
            if (xorderDetailInfo != null)
            {
                this.txtOriginalQty.Text = base.GetPreferenceDigit(xorderDetailInfo.OriginalQty);
                this.ddlStatus.SelectedValue = xorderDetailInfo.Status;
                this.txtProcessedQty.Text = base.GetPreferenceDigit(xorderDetailInfo.ProcessedQty);
                this.txtShippedQty.Text = base.GetPreferenceDigit(xorderDetailInfo.ShippedQty);
                this.txtSkuID.Text = xorderDetailInfo.SkuID;
                this.txtToProcessedQty.Text = base.GetPreferenceDigit(xorderDetailInfo.ToProcessQty);
                base.DataEntityViewState = xorderDetailInfo;
            }
        }
    }
}

